<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The CommonMark\CQL class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="commonmark-parser.finish.html">« CommonMark\Parser::finish</a></li>
      <li style="float: right;"><a href="commonmark-cql.construct.html">CommonMark\CQL::__construct »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.cmark.html">CommonMark</a></li>
    <li>The CommonMark\CQL class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.commonmark-cql" class="reference">

 <h1 class="title">The CommonMark\CQL class</h1>
 

 <div class="partintro"><p class="verinfo">(cmark &gt;= 1.1.0)</p>


  <div class="section" id="commonmark-cql.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    CommonMark Query Language is a DSL for describing how to travel through a CommonMark Node tree implemented as a parser and compiler for a small set of instructions, and a virtual machine for executing those instructions.
   </p>
   <p class="formalpara">
    <h5 class="title">Paths:</h5>
     <p class="para">
      In it&#039;s most simplistic form, a CQL query combines the following paths and <code class="literal">/</code> to describe how to travel through a tree:
      <ul class="simplelist">
       <li class="member">firstChild</li>
       <li class="member">lastChild</li>
       <li class="member">previous</li>
       <li class="member">next</li>
       <li class="member">parent</li>
      </ul>
      For example, <code class="literal">/firstChild/lastChild</code> would travel to the last child node of the first child node.
     </p>
   </p>
   <p class="formalpara">
   <h5 class="title">Loops</h5>
   <p class="para">
    CQL can be instructed to loop, for example through the children of, or siblings to a particular node, by using the path <code class="literal">children</code>, or <code class="literal">siblings</code>. For example, <code class="literal">/firstChild/children</code> will travel to all the children of the first child node.
   </p>
   </p>
   <p class="formalpara">
    <h5 class="title">Subqueries</h5>
     <p class="para">
      CQL can be instructed how to travel by using a subquery like <code class="literal">[/firstChild]</code>. For example, <code class="literal">/firstChild/children[/firstChild]</code> will travel to the first child node of all the children of the first child node.
     </p>   
   </p>
   <p class="formalpara">
    <h5 class="title">Loop Constraints</h5>
     <p class="para">
      While looping, CQL can be instructed to constrict the travelled path to nodes of particular type. For example <code class="literal">/children(BlockQuote)</code> will travel to the children of a node where the type is <code class="literal">BlockQuote</code>. The following types are recognized (case insensitively):
      <ul class="simplelist">
       <li class="member">BlockQuote</li>
       <li class="member">List</li>
       <li class="member">Item</li>
       <li class="member">CodeBlock</li>
       <li class="member">HtmlBlock</li>
       <li class="member">CustomBlock</li>
       <li class="member">Paragraph</li>
       <li class="member">Heading</li>
       <li class="member">ThematicBreak</li>
       <li class="member">Text</li>
       <li class="member">SoftBreak</li>
       <li class="member">LineBreak</li>
       <li class="member">Code</li>
       <li class="member">HtmlInline</li>
       <li class="member">CustomInline</li>
       <li class="member">Emphasis</li>
       <li class="member">Strong</li>
       <li class="member">Link</li>
       <li class="member">Image</li>
      </ul>
      Types may be used as a union, for example <code class="literal">/children(BlockQuote|List)</code> will travel to the children of a node where the type is <code class="literal">BlockQuote</code> or <code class="literal">List</code>. Types, or unions of types, may be also negated. For example <code class="literal">/children(~BlockQuote)</code> will travel to the children of a node where the type is not <code class="literal">BlockQuote</code>, and <code class="literal">/children(~BlockQuote|Paragraph)</code> will travel to the children of a node where the type is not <code class="literal">BlockQuote</code> or <code class="literal">Paragraph</code>
     </p>
   </p>
   <p class="formalpara">
    <h5 class="title">Path Constraints</h5>
     <p class="para">
      CQL can be instructed to create a loop to travel to a node of a particular type, at a particular path. For example, <code class="literal">/firstChild(BlockQuote)</code> will travel to the first child node where the type is <code class="literal">BlockQuote</code>. Note that like other loops for <code class="literal">children</code> and <code class="literal">siblings</code>, this kind of path can only be followed by a subquery.
     </p>
   </p>
   <p class="formalpara">
    <h5 class="title">Implementation Notes</h5>
    <p class="para">
    While CQL has been implemented as part of the PHP CommonMark extension, it stands separately from PHP and does not use PHP&#039;s virtual machine or internal representation of values.
   </p> 
   </p>
  </div>


  <div class="section" id="commonmark-cql.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">CommonMark\CQL</strong>
     </span>
     {</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constructor */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="commonmark-cql.construct.html" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>)</div>

    
    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="commonmark-cql.invoke.html" class="methodname">__invoke</a></span>(<span class="methodparam"><span class="type"><a href="class.commonmark-node.html" class="type CommonMark\Node">CommonMark\Node</a></span> <code class="parameter">$root</code></span>, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$handler</code></span>)</div>

   }</div>


  </div>

 </div>

  






  







<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="commonmark-cql.construct.html">CommonMark\CQL::__construct</a> — CQL Construction</li><li><a href="commonmark-cql.invoke.html">CommonMark\CQL::__invoke</a> — CQL Execution</li></ul>
</div>
</div></div></body></html>